package cn.rknn.iot.engine.mqtt;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * 可以一种topic，写一个IMqttMessageListener实现类，方便业务扩展
 */

@Slf4j
@Service
@EnableAsync
public class MqttMessageListener implements IMqttMessageListener {

    @Override
    @Async("mqttTaskExecutor") //可以配置线程池
    public void messageArrived(String topic, MqttMessage message) throws Exception {
        log.info("Received message on topic: {}" ,topic);
        log.info("Message content: {}" , new String(message.getPayload()));
    }

}